package cn.tedu.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import cn.tedu.entity.Dept;
import cn.tedu.utils.DBUtils;

public class DeptDao {
	public List<Dept> findAll(){
		ArrayList<Dept> depts=new ArrayList<>();
		
		//获取连接
		try (Connection conn = DBUtils.getConn();) {
			Statement stat=conn.createStatement();
			ResultSet rs=stat.executeQuery("select * from dept");
			while (rs.next()) {
				int deptno=rs.getInt("deptno");
				String dname=rs.getString("dname");
				String loc=rs.getString("loc");
				//封装到对象里面并添加到集合中
				depts.add(new Dept(deptno, dname, loc));
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return depts;
	}
}
